package me.vudu.Conflict.Blocks;



import me.vudu.Conflict.ConflictPlugin;


import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.getspout.spoutapi.block.design.Texture;
import org.getspout.spoutapi.inventory.SpoutItemStack;
import org.getspout.spoutapi.player.SpoutPlayer;

/**
 * der VuduBrick!
 * @author vwendel
 *
 */
public class BaseBlockGiverBlock extends ConflictBlock{

	
	public BaseBlockGiverBlock(Plugin plugin) {
	    super(plugin, "BaseBlockGiverBlock", ConflictPlugin.BASEBLOCKID, "", 16);
	    this.getBlockDesign().setTexture(plugin, new Texture(plugin, "http://tossat.de/~mcbukkit/images/bbgiver.png", 16, 16, 16));
	    this.setItemDrop(new SpoutItemStack(new ItemStack(37,0)));
	    if(ConflictPlugin.isCoop){
	    	ConflictPlugin.allowBBB=false;
	    }
	}
	
	/**
	 * false, damit man darauf bauen kann
	 */
	 public boolean onBlockInteract(World world, int x, int y, int z, SpoutPlayer player) {
	     return false;
	 }
	 
	   public void onBlockClicked(World world, int x, int y, int z, SpoutPlayer player) {
		   if(ConflictPlugin.playerIsInTeam(player).equals("red")){
			   if(ConflictPlugin.allowBBR){
				   player.getInventory().addItem(new SpoutItemStack(ConflictPlugin.baseBlockRed, 1));
				   ConflictPlugin.allowBBR = false; // nur 1x
				   Bukkit.getServer()
							.broadcastMessage("Spieler " + ChatColor.RED + player.getName() + ChatColor.WHITE + " hat den roten BaseBlock!");
			   }
		   }
		   if(ConflictPlugin.playerIsInTeam(player).equals("blue")){
			   if(ConflictPlugin.allowBBB){
				   player.getInventory().addItem(new SpoutItemStack(ConflictPlugin.baseBlockBlue, 1));
				   ConflictPlugin.allowBBB = false; // nur 1x
				   Bukkit.getServer()
							.broadcastMessage("Spieler " + ChatColor.BLUE + player.getName() + ChatColor.WHITE + " hat den blauen BaseBlock!");
			   }
		   }
		   
		   if(!ConflictPlugin.allowBBR && ! ConflictPlugin.allowBBB){
			   world.getBlockAt(x, y, z).breakNaturally(new ItemStack(37,0));
		   }
	   }
	 
	   
	 
}
